//
//  YYJLPersonalDetailViewController.m
//  YuanyangJinlou
//
//  Created by mac004 on 2017/1/9.
//  Copyright © 2017年 suli19910309@qq.com. All rights reserved.
//

#import "YYJLPersonalDetailViewController.h"
#import "YYJLTestController.h"
#import "YYJLMonthlyTestCell.h"
@interface YYJLPersonalDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * _tableview;
    UIView  * blureyView;//覆盖层
    UIView  * tipView;//提示框
    UIWindow                    *_selectWindow;
}
@end

@implementation YYJLPersonalDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavBar];
    [self onCreateUI];
}
#pragma mark - UI
- (void)setupNavBar {
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"fanhui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]style:UIBarButtonItemStylePlain target:self action:@selector(navigationBackButton)];
    
}
-(void)onCreateUI{
    float heith = 0;
    heith = 80*PERCEN;
   
    
   _tableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64-44*PER_HEIGHT)  style:UITableViewStylePlain];
    
    
    _tableview.delegate=self;
    _tableview.dataSource=self;
    _tableview.backgroundColor=[UIColor clearColor];
     _tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableview];
    
    

    

   
}
-(void)navigationBackButton {
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark--tableview
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPathP{
    YYJLTestController * test =[[YYJLTestController alloc]init];
    if (self.isPersonal) {
        test.testType=PersonalTest;
        [self.navigationController pushViewController: test animated:YES];
        return;
    }else{
     
        [self addTipView];
    }
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 12;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 131*PER_HEIGHT;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YYJLMonthlyTestCell* cell=[tableView dequeueReusableCellWithIdentifier:@"cel"];
    if (!cell) {
        cell=[[YYJLMonthlyTestCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.backgroundColor=[UIColor clearColor];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.isPersonal=_isPersonal;
    return cell;
}
-(void)addTipView{
    
  
    _selectWindow = [[UIWindow alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.frame];
    _selectWindow.backgroundColor = [UIColorFromHex(0x000000) colorWithAlphaComponent:.4];
    
    [_selectWindow makeKeyAndVisible];
    
    tipView =[[UIView alloc]initWithFrame:CGRectMake(37*PER_WIDTH, 160*PER_HEIGHT, SCREEN_WIDTH-74*PER_WIDTH, 350*PER_HEIGHT)];
    tipView.layer.cornerRadius=10;
    tipView.backgroundColor=[UIColor whiteColor];
    [_selectWindow addSubview:tipView];
    
    
    //删除按钮
    UIButton *guanbiBtn=[MyControl createButtonWithFrame:CGRectMake(tipView.width-33*PER_WIDTH, 10*PER_HEIGHT, 23*PER_WIDTH, 23*PER_WIDTH) ImageName:@"ico_guanbi" Target:self Action:@selector(guanbi) Title:@""];
    [tipView addSubview:guanbiBtn];
    
    
    UILabel * tipLb=[MyControl createLabelWithFrame:CGRectMake(0, 65*PER_HEIGHT, tipView.width, 16*PER_HEIGHT) Font:16 Text:@"珠宝礼仪规范实训检测模拟卷(2)" Color:TINK_COLOR];
    tipLb.textAlignment=NSTextAlignmentCenter;
    [tipView addSubview:tipLb];
    
    UILabel * sureLb=[MyControl createLabelWithFrame:CGRectMake(0, tipLb.bottom+64*PER_HEIGHT, tipView.width, 13*PER_HEIGHT) Font:13 Text:@"上次没有答完题" Color:BLACK_COLOR];
    sureLb.textAlignment=NSTextAlignmentCenter;
    
    [tipView addSubview:sureLb];
    
    //重新开始按钮
    UIButton * cancelBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame=CGRectMake(90.5*PER_WIDTH, tipView.height-61*PER_HEIGHT, 120*PER_WIDTH, 36*PER_WIDTH);
    cancelBtn.layer.cornerRadius=cancelBtn.height/2;
    cancelBtn.backgroundColor=TINK_COLOR;
    cancelBtn.titleLabel.font=[UIFont fontWithName:HSGBW3 size:16];
    cancelBtn.titleLabel.font=[UIFont systemFontOfSize:16*PER_HEIGHT];
    [cancelBtn setTitle:@"重新开始" forState:0];
    [cancelBtn setTitleColor:WHITE_COLOR forState:0];
    [cancelBtn addTarget:self action:@selector(cancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [tipView addSubview:cancelBtn];
    
    //继续作答按钮
    UIButton * continueBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    continueBtn.frame=CGRectMake(90.5*PER_WIDTH, tipView.height-61*PER_HEIGHT-56*PER_HEIGHT, 120*PER_WIDTH, 36*PER_WIDTH);
    continueBtn.layer.cornerRadius=cancelBtn.height/2;
    continueBtn.layer.borderColor=TINK_COLOR.CGColor;
    continueBtn.layer.borderWidth=1;
    continueBtn.titleLabel.font=[UIFont fontWithName:HSGBW3 size:16];
    continueBtn.titleLabel.font=[UIFont systemFontOfSize:16*PER_HEIGHT];
    [continueBtn setTitle:@"继续作答" forState:0];
    [continueBtn setTitleColor:UIColorFromHex(0xa21b18)  forState:0];
    [continueBtn addTarget:self action:@selector(continueBtn) forControlEvents:UIControlEventTouchUpInside];
    [tipView addSubview:continueBtn];
    
    
    
    
}
#pragma mark--tipviewAction
-(void)guanbi{
    [tipView removeFromSuperview];
    [self removeFromWindow];
}
-(void)continueBtn{
    [self guanbi];
    YYJLTestController * test =[[YYJLTestController alloc]init];
       test.testType=SimulationTest;
         [self.navigationController pushViewController: test animated:YES];
}
-(void)cancelBtn{
    [self guanbi];
    YYJLTestController * test =[[YYJLTestController alloc]init];
    test.testType=SimulationTest;
    [self.navigationController pushViewController: test animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)removeFromWindow
{
    NSMutableArray *windows = [[NSMutableArray alloc]initWithArray:[UIApplication sharedApplication].windows];
    if ([windows containsObject:_selectWindow]) {
        [windows removeObject:_selectWindow];
        _selectWindow = nil;
    }
    
    [windows enumerateObjectsUsingBlock:^(UIWindow  *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.windowLevel == UIWindowLevelNormal && [obj isKindOfClass:[UIWindow class]] && obj.isHidden == NO) {
            [obj makeKeyAndVisible];
            *stop = YES;
        }
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
